﻿package org.rkuk.kasutil.timeline.conditions 
{
	import org.rkuk.kasutil.timeline.ITickInfo;
	import org.rkuk.kasutil.timeline.ITicker;
	import org.rkuk.kasutil.timeline.Timeline;
	/**
	 * 延迟一定时间后开始刷新
	 * @author rkuk
	 */
	public class Delay implements ITickerUpdateCondition
	{
		private var _delayTime:int;
		private var _isDelayed:Boolean;
		private var _startTime:Number;
		
		/**
		 * 构造函数
		 * @param	delayTime	刷新的延迟量
		 */
		public function Delay(delayTime:int) 
		{
			_delayTime = delayTime;
			_isDelayed = false;
			_startTime = NaN;
		}
		
		/* INTERFACE org.rkuk.kasutil.timeline.conditions.ITickerUpdateCondition */
		
		/**
		 * 实现ITicker在注册到Timeline之后，延迟一定时间之后再开始刷新。
		 * @param	timeline	发出刷新信号的Timeline对象
		 * @param	ticker		可能将要被刷新的ITicker对象
		 * @param	tickInfo	Timeline发出刷新信号时的时间信息
		 * @return	true表示ITicker需要被刷新，false表示ITicker不需要被刷新
		 */
		public function isNeedUpdate(timeline:Timeline,ticker:ITicker, tickInfo:ITickInfo):Boolean
		{
			if (!_isDelayed)
			{
				if (isNaN(_startTime))
				{
					_startTime = tickInfo.currentTime;
					return false;
				}
				
				if (tickInfo.currentTime-_startTime >= _delayTime)
					_isDelayed = true;
					
				return _isDelayed;
			}
			
			return true;
		}		
	}

}